using System;
using System.Collections.Generic;
using System.Xml;
using System.Data;
using System.Diagnostics;
using Adoor.Expression;
using Adoor.Object;
using Adoor.Object.Domain;
using Adoor.Object.Entity;
using Adoor.Relational;
using Adoor.Data;  // For SmartKey

namespace Adoor.Object.Relational
{
    public class CustomKeyFactory<TEntity> : CustomKeyMapping<TEntity>, IOidFactory<TEntity>
    {
        public CustomKeyFactory(Adoor.Object.Domain.EntityData entityData, XmlNode metadata)
            : base(entityData, metadata)
        {
            Adoor.Object.Domain.EntityData parentData = this.EntityData.ParentData;
            while (parentData != null)
            {
                parentData.PolymorphismManager.AddOidData(this);
                parentData = parentData.ParentData;
            }

            if (this.EntityData.PolymorphismManager != null)
                this.EntityData.PolymorphismManager.AddOidData(this);
        }

        public IOidData OidData
        {
            get { return this; }
        }

        public object Discriminator
        {
            get { return this.EntityData.EntityType.Name + ':'; }
        }

        public virtual void CreateKey(IEntityState state)
        {
            // nothing
        }
    }

}
